package com.foreveross.project.projectonline.web.controller;

import com.foreveross.project.projectonline.config.NeedLogin;
import com.foreveross.project.projectonline.model.TpMgtUser;
import com.foreveross.project.projectonline.service.MgtUserService;
import com.jfinal.aop.Before;
import com.jfinal.plugin.spring.Inject;
import com.jfinal.plugin.spring.IocInterceptor;

/**
 * 
 * @author Administrator
 *
 */
@Before(IocInterceptor.class)
@NeedLogin
public class MyInfoController extends BaseController {
	
	@Inject.BY_NAME
	MgtUserService mgtUserService;
	
	public void index() {
		TpMgtUser user = (TpMgtUser)getAttr("LOGIN_USER");
		setAttr("user", user);
		render("/pages/myInfo.html");
	}
	
	public void changePassword(){
		TpMgtUser user = (TpMgtUser)getAttr("LOGIN_USER");
		int b = mgtUserService.changePasswrod(user, getPara("OLD_PASSWORD"), getPara("pwd"));
		if(b == 1){
			setAttr("b", true);
			setAttr("info","密码修改成功！");
		} else if (b == 3){
			setAttr("b", false);
			setAttr("info","修改密码失败！旧密码不对。");
		}  else {
			setAttr("b", false);
			setAttr("info","系统异常！请联系管理员。");
		}
		
		index();
	}
}
